package com.dream.wukong.common.core.interfaces.jdbc;

import com.dream.wukong.common.core.interfaces.dao.PageResult;

import java.util.List;
import java.util.Map;

/**
 * @Author: wuyichao
 * @Description:
 * @Date: Created in 11:04 2018/9/18.
 * @Modified:
 * 本地化JDBC分页查询，分两种类型：直接传入SQL,或者根据SQL对应的KEY;
 */

public  interface INativeQuery {

    public final static String CACHE_KEY_PREFIX = INativeQuery.class.getSimpleName()+":";
    /**
     *
     * @param sqlKey
     * @param map
     * @return
     */
    public abstract List<Map<String, Object>> selectAllList(String sqlKey,
                                                            Map<String, Object> map);

    /**
     * @param sqlKey
     * @param map
     * @param offset
     * @param limit
     * @return offset+1~offset+limit
     */
    public abstract List<Map<String, Object>> selectPageList(String sqlKey,
                                                             Map<String, Object> map, int offset, int limit);

    /**
     * @param map
     * @param offset
     * @param limit
     * @return offset+1~offset+limit
     */
    public abstract List<Map<String, Object>> selectPageListBySql(String sql,
                                                                  Map<String, Object> map, int offset, int limit) ;


    public abstract <T> List<T> selectPageListBySql(String sql,
                                                    Map<String, Object> map, int offset, int limit,Class<T> cls);

    /**
     * @param sqlKey
     * @param map
     * @return
     */
    public abstract List<Map<String, Object>> selectPageList(String sqlKey,
                                                             Map<String, Object> map);

    /**
     *
     * @param sqlKey
     * @param map
     * @return
     * @throws Exception
     */
    public abstract Long selectCount(String sqlKey, Map<String, Object> map);

    /**
     *
     * @param map
     * @return
     * @throws Exception
     */
    public abstract Long selectCountBySql(String sql, Map<String, Object> map);

    /**
     * select * from table where user_id = :userId
     *
     * @param sql
     * @param map
     */
    public abstract List<Map<String, Object>> queryForList(String sql,
                                                           Map<String, Object> map);

    /**
     * select * from table where user_id = :userId
     *
     * @param sql
     * @param map
     */
    public abstract Map<String, Object> queryForMap(String sql,
                                                    Map<String, Object> map);

    /**
     *
     * EXAMPLE: sql:select COUNT(1) cnt from table where user_id = :userId map:
     * { userId : "1"} requiredType : Long.class return Long value of cnt
     *
     * @param sql
     * @param map
     * @param requiredType
     * @return
     */
    public abstract <T> T queryForObject(String sql, Map<String, Object> map,
                                         Class<T> requiredType);

    /**
     * @param sqlKey
     * @param map
     * @param pageResult
     * @param cls
     * @return
     */
    public abstract <T> PageResult<T> selectPageResult(String sqlKey,
                                                       Map<String, Object> map, PageResult<T> pageResult,Class<T> cls);

    /**
     * @param sql
     * @param map
     * @param pageResult
     * @param cls
     * @return
     */
    public abstract <T> PageResult<T> selectPageResultBySql(String sql,
                                                            Map<String, Object> map, PageResult<T> pageResult,Class<T> cls);
}